<div class="row">
	<div class="col-md-12">
		<form id="roleEditForm" action="${request.contextPath}/system/authority/role/update" method="post" onsubmit="return false">
			<input type="hidden" id="id" name="id" value="${role.id}">
			<div class="box-body">
				<div class="form-group">
					<label id="roleNameLabel">角色名称</label>
					<input type="text" class="form-control" name="name" id="roleName" value="${role.name}" placeholder="输入角色名称...">
				</div>
				<div class="form-group">
					<label id="roleDescriptionLabel">描述</label>
					<input type="text" class="form-control" name="description" id="roleDescription" value="${role.description}" placeholder="输入描述...">
				</div>
				<div class="form-group">
					<label id="roleSeqLabel">排序号</label>
					<input type="text" class="form-control" name="seq" id="roleSeq" value="${role.seq}" placeholder="输入排序号...">
				</div>
				<div class="form-group">
					<label id="roleRemarkLabel">备注</label>
					<input type="text" class="form-control" name="remark" id="roleRemark"  value="${role.remark}" placeholder="输入备注...">
				</div>
				<div class="error-message text-center" >
					<span class="error-icon"></span>
					<span id="error-msg" class="error-msg" ></span>
				</div>
             </div>
			<div class="box-footer">
				<div class="pull-right">
               		<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 更新</button>
               		<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 关闭</button>
				</div>
          	</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
		$.post(form.action, $form.serialize(),function(result) {
			if (result.success) {
				$("#lgModal").modal('hide');
	        	alertMsg(result.message,"success");
	        	reloadTable(role_tab,{});
			} else {
				$form.find(".error-msg").show();
				$form.find(".error-msg").html(result.message);
			}
		}, 'json');
	}
}

$(function() {
	$roleEditForm = $("#roleEditForm");
	$roleEditForm.validate({
		rules: {
			name: {
				required: true
			},
			description: {
				required: true
			},
			seq: {
				required: true
			}
		},
		messages: {
			name:{
				required:"角色名称不能为空！"
			},
			description: {
				required: "描述不能为空！"
			},
			seq: {
				required: "排序号不能为空！"
			}
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:".error-msg",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$roleEditForm.find(".error-msg").html(errorList[0].message);
			}else{
				$roleEditForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>